import { Select } from 'antd';
import React, { Component } from 'react';
import { getChannels } from 'api/channels';
const { Option } = Select;
export default class Channel extends Component {
	state = {
		channels: [],
	};
	async componentDidMount() {
		const { channels } = await getChannels();
		this.setState({ channels });
	}
	render() {
		const { channels } = this.state;
		const { style = {}, ...restProps } = this.props;

		return (
			<Select
				placeholder="请选择频道"
				{...restProps}
				allowClear
				style={{ width: 200, ...style }}
			>
				{channels.length &&
					channels.map((channel) => (
						<Option value={channel.id} key={channel.id}>
							{channel.name}
						</Option>
					))}
			</Select>
		);
	}
}
